//
//  CustomMessageCell.m
//  SeaMelonSeeds_Counselor
//
//  Created by 尤振宇 on 2017/7/24.
//  Copyright © 2017年 杨笑. All rights reserved.
//

#import "CustomMessageCell.h"
#import "Tool.h"

@implementation CustomMessageCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier model:(id<IMessageModel>)model
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier model:model];
    if (self) {
        
        [self.bubbleView addSubview:self.btn];
        [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self.bubbleView.textLabel);
        }];
        

//        [self.backView addSubview:self.text];
//        [self.text mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.backView).with.offset(15);
//            make.centerX.equalTo(self.backView);
//        }];
//        
//        CGFloat labelW = [model.text widthForFontSize:self.text.font.pointSize andHeight:20];
//        
//        [self.bubbleView.backgroundImageView addSubview:self.backView];
//        [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.edges.equalTo(self.bubbleView.backgroundImageView);
//            make.width.equalTo(@(labelW + 30));
//        }];
        
    }
    return self;
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.bubbleView.textLabel.textColor = [@"65ACFE" colorWithHexString];

}

-(void)setModel:(id<IMessageModel>)model
{
    [super setModel:model];
}

-(void)action_custom:(UIButton *)btn
{
    if (self.buttonAction) {
        self.buttonAction(btn);
    }
}
//
//-(void)setButtons:(NSArray <NSString *>*)titles
//{
//    [self.btn1 removeFromSuperview];
//    [self.btn2 removeFromSuperview];
//    
//    if (titles.count == 2) {
//        UIButton *btn1 = [self button];
//        UIButton *btn2 = [self button];
//        
//        [self.backView addSubview:btn1];
//        [self.backView addSubview:btn2];
//        
//        [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.text.mas_bottom).with.offset(8);
//            make.left.equalTo(self.text);
//            make.width.equalTo(self.text).dividedBy(2).width.offset(-5);
//            make.height.equalTo(@25);
//        }];
//        
//        [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.text.mas_bottom).with.offset(8);
//            make.right.equalTo(self.text);
//            make.width.equalTo(self.text).dividedBy(2).width.offset(-5);
//            make.height.equalTo(@25);
//        }];
//        
//        [btn1 setTitle:@"查看详情" forState:(UIControlStateNormal)];
//        [btn1 setTitle:@"查看详情" forState:(UIControlStateNormal)];
//        
//        self.btn1 = btn1;
//        self.btn2 = btn2;
//    }else if (titles.count == 1){
//        UIButton *btn = [self button];
//        
//        [btn setTitle:@"查看详情" forState:(UIControlStateNormal)];
//        [btn mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.equalTo(self.text.mas_bottom).with.offset(8);
//            make.centerX.equalTo(self.text);
//            make.width.equalTo(@65);
//            make.height.equalTo(@25);
//        }];
//        
//        self.btn1 = btn;
//    }
//}
//
//-(UIButton *)button
//{
//    UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
//    button.titleLabel.font = [UIFont systemFontOfSize:13];
//    [button setBackgroundImage:[UIImage imageNamed:@"65ACFE"] forState:(UIControlStateNormal)];
//    return button;
//}
//
//-(void)setModel:(id<IMessageModel>)model
//{
//    [super setModel:model];
//    self.bubbleView.textLabel.text = nil;
//    self.text.text = model.text;
//}
//
//+(CGFloat)cellHeightWithModel:(id<IMessageModel>)model
//{
//    return 105;
//}
//
//-(UIView *)backView
//{
//    if (!_backView) {
//        _backView = [[UIView alloc]init];
//    }
//    return _backView;
//}
//
//-(UILabel *)text
//{
//    if (!_text) {
//        _text = [[UILabel alloc]init];
//        _text.font = [UIFont systemFontOfSize:16];
//    }
//    return _text;
//}

-(UIButton *)btn
{
    if (!_btn) {
        _btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_btn addTarget:self action:@selector(action_custom:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _btn;
}

+(NSString *)Identifier
{
    return @"CustomMessageCell";
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
